package model;

import entity.Department;
import entity.Employee;
import entity.Orders;
import entity.OrdersDetails;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Noi
 */
public class EmployeeFineTableModel extends AbstractTableModel {

    private manager.Manager manager;
    private ArrayList<Employee> alEmployees;

    public EmployeeFineTableModel(manager.Manager manager) {
        this.manager = manager;
        this.alEmployees = new ArrayList<Employee>();
    }

    public void setAlEmployees(ArrayList<Employee> alEmployees) {
        this.alEmployees = alEmployees;
        this.fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return this.alEmployees.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Employee employee = this.alEmployees.get(rowIndex);
        Department department = this.manager.getDepartmentManager().getByID(employee.getDepartmentID());
        ArrayList<Orders> alOrders = this.manager.getOrdersManager().getByEmployeeID(employee.getEmployeeID());
        ArrayList<OrdersDetails> alDetails = this.manager.getOrdersDetailsManager().getListOrdersDetailsPaid(alOrders);
        
        float count = 0;
        
        for(OrdersDetails details: alDetails) {
            count += details.getMoney();
        }
        switch(columnIndex) {
            case 0:
                return employee.getEmployeeID();
            case 1:
                return employee.getEmployeeName();
            case 2:
                return department.getDepartmentName();
            case 3:
                return count;
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Employee ID";
            case 1:
                return "Employee Name";
            case 2:
                return "Department";
            case 3:
                return "Fines";
            default:
                return null;
        }
    }

    public Employee get(int selectedRow) {
        return this.alEmployees.get(selectedRow);
    }
}
